# sudo kubectl -n kubesphere-system patch svc ks-apiserver -p '{"spec":{"type":"NodePort","ports":[{"name":"ks-apiserver","port":80,"protocal":"TCP","targetPort":9090,"nodePort":30881}]}}'

# 定义要检查的端口列表
port_list=("8000" "8001" "9092")


# 查找占用指定端口的进程ID
find_process_id() {
  local port="$1"
  local process_id=$(netstat -tuln | awk -v p="$port" '$4 ~ (":"p"$") {print $NF}' | sed 's/[^0-9]*//g')
  echo "$process_id"
}

# 终止指定进程
kill_process() {
  local process_id="$1"
  if [[ -n "$process_id" ]]; then
    echo "Killing process $process_id"
    kill -9 "$process_id"
    return 0
  else
    echo "No process is using port $port."
    return 1
  fi
}

process_id=$(find_process_id "$port")
kill_process "$process_id"


